package com.ghca.myinfo.spider.pipeline;

import com.ghca.myinfo.market.entities.TenderNotice;
import com.ghca.myinfo.market.repositories.TenderNoticeRepository;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/1/24.
 */

@Component
public class TenderNoticeePipeline implements Pipeline{

    @Resource
   private TenderNoticeRepository tenderNoticeRepository;

    @Override
    public void process(ResultItems resultItems, Task task) {
        resultItems.getAll().forEach((key, value) -> {
            if(key.equals("tenderNotices")) {
                List<TenderNotice> list = (List<TenderNotice>) value;
                list.forEach((item)->{
                    if((item.getType()&1) == 1) {
                        tenderNoticeRepository.save(item);
                    }
                });
            }
        });

    }
}
